﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ADC.BL;
using System.Text;
using ADC.DAL;

namespace ADC.Web
{
    public partial class MasterHome : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                BindData();
            }
        }

        private void BindData()
        {
            // Bind Support
            List<Support> supports = SupportFactory.GetAll();
            ListViewProducts.DataSource = supports;
            ListViewProducts.DataBind();

            // Get Product Types
            List<ProductType> productTypes = ProductTypeFactory.SelectAll();

            if (productTypes.Count <= 0) return;

            StringBuilder strMenu = new StringBuilder();
            for (int i = 0; i < productTypes.Count; i++)
            {
                if(i == (productTypes.Count - 1))
                {
                    strMenu.Append("<div class='menu-right-item'><a href='ListProduct.aspx?type="  + productTypes[i].ProductTypeID + "'>");
                    strMenu.Append(productTypes[i].Title);
                    strMenu.Append("</a></div>");
                } else
                {
                    strMenu.Append("<div class='menu-right-item'><a href='ListProduct.aspx?type=" + productTypes[i].ProductTypeID + "'>");
                    strMenu.Append(productTypes[i].Title);
                    strMenu.Append("</a></div><div class='menu-item-sep'></div>");
                }
            }
            lblMenu.Text = strMenu.ToString();
        }

    }
}